package com.bsoft.hospitalchs.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bsoft.hospitalchs.R;
import com.bsoft.hospitalchs.model.LeftMenuBean;

import java.util.List;

/**
 * Created by 泅渡者
 * Created on 2017/5/18.
 */

public class LeftmenuAdapter extends BaseAdapter {
    private Context context;
    private List<LeftMenuBean> leftMenuBeen;
    private int checked = 0;
    public LeftmenuAdapter(Context context, List<LeftMenuBean> leftMenuBeen) {
        this.context = context;
        this.leftMenuBeen = leftMenuBeen;
    }

    @Override
    public int getCount() {
        return leftMenuBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return leftMenuBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setChecked(int checked) {
        this.checked = checked;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.menu_left_item,null);
            viewHolder = new ViewHolder(convertView);
            if(checked==position){
                viewHolder.tv_menu.setText(leftMenuBeen.get(position).getMenuName());
                viewHolder.tv_menu.setTextColor(Color.parseColor("#1372A2"));
            }else{
                viewHolder.tv_menu.setText(leftMenuBeen.get(position).getMenuName());
                viewHolder.tv_menu.setTextColor(Color.parseColor("#666666"));
            }
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
            if(checked==position){
                viewHolder.tv_menu.setText(leftMenuBeen.get(position).getMenuName());
                viewHolder.tv_menu.setTextColor(Color.parseColor("#1372A2"));
            }else{
                viewHolder.tv_menu.setText(leftMenuBeen.get(position).getMenuName());
                viewHolder.tv_menu.setTextColor(Color.parseColor("#666666"));
            }
        }
        return convertView;
    }
    class ViewHolder{
        TextView tv_menu;
        public ViewHolder(View view) {
            tv_menu = (TextView)view.findViewById(R.id.tv_menu);
        }
    }
}
